home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / ada.h < prev    next >
C/C++ Source or Header  |  1996-01-30  |  7KB  |  268 lines

  1. /*
  2.  * Copyright (C) 1985-1992  New York University
  3.  * 
  4.  * This file is part of the Ada/Ed-C system.  See the Ada/Ed README file for
  5.  * warranty (none) and distribution info and also the GNU General Public
  6.  * License for more details.
  7.  
  8.  */
  9. #include "config.h"
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <malloc.h>
  13. #include <ctype.h>
  14. #include <string.h>
  15. #include "constant.h"
  16.  
  17. #define TABFILE "ada.t"
  18. #define CONSTANTFILE "constant.h"
  19.  
  20. #define EOFT "$EOF"
  21. #define ERROR_SYM 0
  22. #define MAXLINE 120
  23. #define MAX_AST 4
  24.  
  25. #define NUM_LINES 20
  26.  
  27.  
  28.  
  29. /* Structure definitions */
  30. struct namelistmap {
  31.     short num;
  32.     char *name;
  33.     struct namelistmap *nextlist;
  34.     struct namelistmap *nextmap;
  35.     };
  36.  
  37. struct token {
  38.     short index;
  39.     Span_s span;
  40.     };
  41.  
  42. struct prsstack {
  43.     short symbol;
  44.     struct prsstack *prev;
  45.     union {
  46.     Node ast;
  47.     struct token *token;
  48.     } ptr;
  49.     };
  50. struct two_pool {
  51.     struct two_pool *link;
  52.     union {
  53.     int reduction;
  54.     int state;
  55.     Node node;    
  56.     } val;
  57.     };
  58.  
  59. struct tmptok {
  60.     struct token *link;
  61.     };
  62.  
  63. struct tmpnode {
  64.     short kind;        /* set to AS_FREE when first placed on stack */
  65.     short count;
  66.     Span_s span;
  67.     Node link;
  68.     };
  69.  
  70. struct tmpast {
  71.     Node *link;
  72.     };
  73.  
  74.  
  75.  
  76.  
  77.  
  78. /* Declarations of functions needed */
  79. extern struct prsstack *(*prsalloc)(unsigned),*copytoken();
  80. extern char *find_name();
  81. extern void (*prsfree)(struct prsstack *, struct prsstack *);
  82. extern struct two_pool *(*talloc)(unsigned);
  83. extern void (*tfree)(struct two_pool *, struct two_pool *);
  84. extern struct token *(*tokalloc)(unsigned);
  85. extern void (*tokfree)(struct token *);
  86. extern struct prsstack *gettok();
  87. extern struct two_pool *makenodelist();
  88.  
  89.  
  90. /* Declarations of external variables to be visible */
  91. extern Span lspan, rspan;
  92. extern struct prsstack *prs_stack, *curtok, **tokens;
  93. extern struct two_pool *sta_stack;
  94. extern int tokind, toksiz, tokbottom;
  95. extern FILE  *adafile, *msgfile;
  96. extern Node any_node;
  97. extern int lineno, colno, src_index;
  98. extern char *data, *line, source_buf[NUM_LINES][MAXLINE + 1];
  99. extern short lhs[], rhslen[], def_action[]; 
  100. extern short act_tab1[];
  101. extern long act_tab2[];
  102. extern int symcount;
  103. extern struct namelistmap *numtostrtable[], *strtonumtable[], gramsyms[];
  104. extern char islist_node[], islater_declarative_node[], isbody_node[],
  105.     isval_node[], isast_node[],ispredef_pragma[],isimpldef_pragma[],
  106.     isimmediate_decl_pragma[],iscontext_pragma[],iscompilation_pragma[],
  107.     isafter_libunit_pragma[],istask_pragma[],isrepr_pragma[],
  108.     *overloadable_operators[];
  109. extern int redopt, erropt, termopt, debugopt, trcopt;
  110.  
  111. /* Macros */
  112. #define MIN(a,b) (((a) < (b)) ? (a) : (b))
  113. #define MAX(a,b) (((a) > (b)) ? (a) : (b))
  114.  
  115. #define ISTOKEN(node)      ((node)->symbol <= EOFT_SYM)
  116.  
  117.  
  118.  
  119. /* Macros for storage allocation */
  120. #define PRSALLOC() (*prsalloc)(sizeof(struct prsstack))
  121. #define PRSFREE (*prsfree)
  122. #define TALLOC() (*talloc)(sizeof(struct two_pool))
  123. #define TFREE (*tfree)
  124. #define TOKALLOC() (*tokalloc)(sizeof(struct token))
  125. #define TOKFREE (*tokfree)
  126.  
  127.  
  128. /* Error recovery: */
  129.  
  130. /* ALWAYS_PREFERRED_SYMS */
  131. #define in_ALWAYS_PREFERRED_SYMS(t) ((t==65) || (t==75) || (t==80) )
  132.  
  133.  
  134. /* Constants*/
  135. #define MAX_LOOK_AHEAD    25
  136. #define MIN_LEN 1
  137. #define RESERVED_SYMS 64
  138.  
  139. /*  
  140.            DEFINE CANDIDATE TYPES
  141.                   
  142. The map CANDIDATES is a multivalued map from the set
  143.     {'delete','subst','merge','spell-subst','insert'} 
  144. to sets of potential candidates for substitution. Each of these is
  145. represented as a structure containing 
  146.             the token symbol, the number of backup tokens and
  147.             a third value.
  148.                                                     */
  149. #define DELETE 1
  150. #define MERGE  2
  151. #define SUBST  3
  152. #define INSERT 4 
  153. #define SPELL_SUBST 5 
  154. #define C_BOUND 6
  155.  
  156.  
  157. /* Structure definitions */
  158.  
  159. typedef struct cand {
  160.     short token_sym,backup_toks,t3 ;
  161.     struct cand *next ;
  162.     } CAND, *PCAND;
  163.  
  164. /*  
  165.            DEFINE STRING TYPES
  166.                                     */
  167. typedef char * STRING ;
  168. typedef struct stringlist {        /* A list of strings        */
  169.     STRING message ;        /* Points to the text        */
  170.     struct stringlist *next ;   /* Points to the next message   */
  171. }   STRINGLIST ;
  172.  
  173.  
  174.  
  175. /* External variables */
  176. extern FILE *errfile;
  177. extern    int TOKSYMS[] ;
  178. extern    int n_TOKSYMS ;
  179. extern    PCAND CANDIDATES[] ;
  180. extern    int n_CANDIDATES[] ;
  181. extern    int MAX_CHECK ;
  182. extern    int BACKUPTOKS ;
  183. extern struct prsstack *PREVTOK;
  184. extern int n_prs, n_prs_stack, n_sta_stack;
  185. #ifndef IBM_PC
  186. extern    int    ACTION_TOKENS[] ;
  187. #endif
  188. #ifdef IBM_PC
  189. extern    char    ACTION_TOKENS[] ;
  190. #endif
  191. extern    int    ACTION_TOKENS_INDEX[] ;
  192. extern    struct two_pool *POSS_TOK ;
  193. extern int  SHIFT_STATE[];
  194. extern int  SHIFT_STATE_INDEX[];
  195. extern int    primopt,scopeopt,secopt ;
  196.  
  197.  
  198.  
  199. /* External function definitions */
  200.  
  201. extern    struct cand *(*candalloc)(unsigned);
  202. extern struct prsstack *tokfromlist();
  203.  
  204. /* Macros */
  205.  
  206.  
  207. #define NEXTTOK (((tokind - tokbottom + 1) % toksiz == 0) ? gettok() : \
  208.     tokfromlist())
  209.  
  210. #define nexttok tokens[(tokind - 1 + toksiz) % toksiz]
  211.  
  212. /* old ADDTOTOP macro deleted and replaced by procedure add_to_top in prserr.c */
  213.  
  214. #define TOKMINUS (tokind = (tokind - 1 + toksiz) % toksiz)
  215.  
  216. #define CANDALLOC() (*candalloc)(sizeof(struct cand))
  217.  
  218. /* #define QUOTE(t) (token_value_des(t) ? "" : "\"") */
  219.  
  220. #define SEMI_SYM 80
  221.  
  222. #define l_span(x) (ISTOKEN(x)    \
  223.         ? (x->ptr.token->span)    \
  224.         : (*(get_left_span_p(x->ptr.ast))))
  225. #define r_span(x) (ISTOKEN(x)    \
  226.         ? (*(make_span(x->ptr.token->span.line,x->ptr.token->span.col + \
  227.                    strlen(namelist(x->ptr.token->index)) -1))) \
  228.         : (*(get_right_span_p(x->ptr.ast))))
  229. #define LLOC(x) (ISTOKEN(x)    \
  230.         ? &(x->ptr.token->span)    \
  231.         : (get_left_span_p(x->ptr.ast)))
  232. #define RLOC(x) (ISTOKEN(x)    \
  233.         ? (make_span(x->ptr.token->span.line,x->ptr.token->span.col + \
  234.                    strlen(namelist(x->ptr.token->index)) -1)) \
  235.         : (get_right_span_p(x->ptr.ast)))
  236.  
  237. #define        NOOP ;
  238.  
  239. #define     is_operator(t)     (( t > CHAR_SYM ) && (t < EOFT_SYM)) 
  240. #define     is_terminal(t)     (t <= EOFT_SYM)
  241. #define     is_reserved(t)     (( t > 0 ) && ( t <= RESERVED_SYMS ) )
  242. /* is_opener is now procedure in prserr.c */
  243.  
  244. #define S_TOKSYMS    (MAX_LOOK_AHEAD * 2)
  245.  
  246. #define TOKSTR(symb)  ((symb != ERROR_SYM) ? namelist(symb) : "ERROR_SYMBOL")
  247.  
  248. /* added for change is spans format (store only for terminal nodes */
  249.  
  250. #define N_D_AST1 1
  251. #define N_D_AST2 2
  252. #define N_D_AST3 4
  253. #define N_D_AST4 8
  254. #define N_D_LIST 16
  255. #define N_D_VAL 32
  256. #define N_D_UNQ 64
  257. #define N_D_TYPE 256
  258.  
  259. #define N_AST2_DEFINED(p) (N_DEFINED[p]&N_D_AST2)
  260. #define N_AST3_DEFINED(p) (N_DEFINED[p]&N_D_AST3)
  261. #define N_AST4_DEFINED(p) (N_DEFINED[p]&N_D_AST4)
  262. #define N_VAL_DEFINED(p) (N_DEFINED[p]&N_D_VAL)
  263. #define N_UNQ_DEFINED(p) (N_DEFINED[p]&N_D_UNQ)
  264. #define N_TYPE_DEFINED(p) (N_DEFINED[p]&N_D_TYPE)
  265. #define N_LIST_DEFINED(p) (N_DEFINED[p]&N_D_LIST)
  266.  
  267. extern int N_DEFINED[] ;
  268.